import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Demo {

    public static void main(String[] args) throws ParseException {
        float shangNianDays;
        float benNianDays = 0;
        Integer firstXinWangNianDay = 7;
        Integer xinWangMaxDay = 12;
        Date d1 = new SimpleDateFormat("yyyy-MM-dd").parse("2015-08-08");
        Date d2 = new SimpleDateFormat("yyyy-MM-dd").parse("2022-01-01");
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(d1);
        c2.setTime(d2);
        int year1 = c1.get(Calendar.YEAR);
        int year2 = c2.get(Calendar.YEAR);
        float ruzhiday = c1.get(Calendar.DAY_OF_YEAR);
        float ruzhibetnow = Math.abs(year1 - year2);

        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year1);
        calendar.roll(Calendar.DAY_OF_YEAR, -1);
        float ru = calendar.get(Calendar.DAY_OF_YEAR);

        // int nowday = c2.get(Calendar.DAY_OF_YEAR);
        // 如果入职年份是当前年份的2年以前
        if (ruzhibetnow > 1 && ruzhibetnow < 7) {
            shangNianDays = ruzhibetnow + firstXinWangNianDay - 1;

            benNianDays = ruzhibetnow + firstXinWangNianDay;
        } else if (ruzhibetnow >= 7) {

            shangNianDays = xinWangMaxDay;
            benNianDays = xinWangMaxDay;
        }
        // 如果入职年份是当前年份的之后的年份
        else if (ruzhibetnow <= 0) {
            // 上年度的天数为0
            shangNianDays = 0;
            // float nianJiaDay = ((12 - Float.valueOf(time.substring(5, 7))) /
            // 12) * firstXinWangNianDay;
            benNianDays = 0;
        }

        // 如果入职年份是当前年份之前的一年
        else {
            // 上年年假的天数为去年入职月数除以一年的月数乘以新旺规定的年假天数
            float nianJiaDay = (float) (Math.floor(((ru - ruzhiday) / ru) * firstXinWangNianDay));
            shangNianDays = Math.round(nianJiaDay);
            benNianDays = firstXinWangNianDay;
            // 本年的年假天数就是新旺规定的年假天数
        }

        System.out.println("上年年假"+shangNianDays);
        System.out.println("本年年假"+benNianDays);

    }
}
